<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="keywords" content="">
    <meta name="description" content="">
    <title>行为日志</title>
    <link rel="stylesheet" href="../../../component/pear/css/pear.css">
    <link rel="stylesheet" href="../../../admin/css/dimples.css">
    <link rel="icon" href="../../../admin/images/favicon.ico" type="image/x-icon"/>
</head>
<body class="pear-container">

<div class="layui-card">
    <div class="layui-card-body">
        <div class="layui-tab layui-tab-card">
            <ul class="layui-tab-title">
                <li class="layui-this">登录日志</li>
                <li>操作日志</li>
            </ul>
            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show">
                    <table style="margin-top: 10px;" id="log-login-table" lay-filter="log-login-table"></table>
                </div>
                <div class="layui-tab-item">
                    <table style="margin-top: 10px;" id="log-operate-table" lay-filter="log-operate-table"></table>
                </div>
            </div>
        </div>
    </div>
</div>
</body>

<script type="text/html" id="log-status">
    {{#if (d.success == "Y") { }}
    <span class="layui-badge dimples-bg-green">成功</span>
    {{# }else if(d.success == "N"){ }}
    <span class="layui-badge dimples-bg-red">失败</span>
    {{# } }}
</script>

<script type="text/html" id="method">
    {{#if (d.method == "GET") { }}
    <span class="layui-badge dimples-tag-green">GET</span>
    {{# }else if(d.method == "POST"){ }}
    <span class="layui-badge dimples-tag-cyan">POST</span>
    {{# }else if(d.method == "PUT"){ }}
    <span class="layui-badge dimples-tag-orange">PUT</span>
    {{# }else if(d.method == "DELETE"){ }}
    <span class="layui-badge dimples-tag-red">DELETE</span>
    {{# } }}
</script>

<script type="text/html" id="log-bar">
    <!--<span {{noPerms('user:online:remove')}}>
    <span class="layui-badge-dot dimples-bg-orange"></span> 无权限
    </span>-->
    <a lay-event="details">
        <i class="layui-icon dimples-edit-area dimples-blue">&#xe7a4;</i>
    </a>
</script>


<script src="../../../component/layui/layui.js"></script>
<script src="../../../component/pear/pear.js"></script>
<script src="../../../component/pear/dimples.js"></script>
<script>
    layui.use(['table', 'form', 'jquery', 'element', 'util', 'popup'], function () {
        let table = layui.table;
        let form = layui.form;
        let popup = layui.popup;

        let MODULE_PATH = BASE_URL + "/system/log/";

        let cols = [
            [
                {title: 'ID', field: 'id', align: 'center', hide: true},
                {title: '描述', field: 'title', align: 'center'},
                {title: '请求方式', field: 'method', align: 'center', templet: '#method'},
                {title: '请求IP', field: 'operateIp', align: 'center'},
                {title: '浏览器', field: 'browser', align: 'center'},
                {title: '操作地址', field: 'operateAddr', align: 'center'},
                {title: '操作系统', field: 'systemOs', align: 'center'},
                {title: '访问时间', field: 'createTime', templet: '#log-createTime', align: 'center'},
                {title: '操作人', field: 'operateName', align: 'center'},
                {title: '访问状态', templet: '#log-status', align: 'center'},
                {title: '操作', templet: '#log-bar', align: 'center', width: 120}
            ]
        ]

        table.render({
            elem: '#log-operate-table',
            url: MODULE_PATH + 'operate',
            page: true,
            request: {
                pageName: 'pageNumber' //页码的参数名称，默认：page
                , limitName: 'pageSize' //每页数据量的参数名，默认：limit
            },
            cols: cols,
            skin: 'line',
            toolbar: false,
            headers: {
                Authorization: getToken()
            },
            response: {
                statusCode: 200 //规定成功的状态码，默认：0
            },
            done: function (res, curr, count) {
                //如果是直接赋值的方式，res即为：{data: [], count: 99} data为当前页数据、count为数据总长度
                if (res.code == 402) {
                    popup.permsDeny();
                }
            }
        });

        table.render({
            elem: '#log-login-table',
            url: MODULE_PATH + 'login',
            page: true,
            request: {
                pageName: 'pageNumber' //页码的参数名称，默认：page
                , limitName: 'pageSize' //每页数据量的参数名，默认：limit
            },
            cols: cols,
            skin: 'line',
            toolbar: false,
            headers: {
                Authorization: getToken()
            },
            response: {
                statusCode: 200 //规定成功的状态码，默认：0
            },
            done: function (res, curr, count) {
                //如果是直接赋值的方式，res即为：{data: [], count: 99} data为当前页数据、count为数据总长度
                if (res.code == 402) {
                    popup.permsDeny();
                }
            }
        });

        form.on('submit(dict-type-query)', function (data) {
            table.reload('dict-type-table', {where: data.field})
            return false;
        });

        table.on('tool(log-operate-table)', function (obj) {
            if (obj.event === 'details') {
                window.info(obj);
            }
        });

        table.on('tool(log-login-table)', function (obj) {
            if (obj.event === 'details') {
                window.info(obj);
            }
        });

        window.info = function (obj) {
            layer.open({
                type: 2,
                title: '详细信息',
                shade: 0,
                area: ['600px', '550px'],
                content: "info.html",
                success: function (layero) {
                    let iframeWin = window[layero.find('iframe')[0]['name']];
                    iframeWin.show(obj.data);
                }
            });
        }
    })
</script>
</html>